<?php
defined('_JEXEC') or die('Restricted access');
 
jimport( 'joomla.html.html.tabs' );
JHtml::_('jquery.framework');
JHtml::_('behavior.keepalive');
JHTML::_('behavior.tooltip'); 
JHtml::_('behavior.framework');

?>
<link href="<?php echo JURI::base(true)?>/components/com_wrd/assets/css/uploadify.css" type="text/css" rel="stylesheet" />
<script type="text/javascript" src="<?php echo JURI::base(true)?>/components/com_wrd/assets/js/jquery-1.4.2.min.js"></script>
<script type="text/javascript" src="<?php echo JURI::base(true)?>/components/com_wrd/assets/js/swfobject.js"></script>
<script type="text/javascript" src="<?php echo JURI::base(true)?>/components/com_wrd/assets/js/jquery.uploadify.v2.1.4.min.js"></script>
<script type="text/javascript">
	//<![CDATA[
	Joomla.submitbutton = function(pressbutton){
		if (pressbutton == 'cancel') {
			submitform( pressbutton );
			return;
		}
		if (pressbutton == 'save') {
			if (document.adminForm.companyname.value == "") {
				alert( 'Must have company name !' );
				document.adminForm.companyname.focus();
				return false;
			}
			submitform( pressbutton );
		}
	}


	jQuery(document).ready(function() {
		jQuery('#logo_upload').uploadify({ 
		    'uploader'  	: '<?php echo JURI::base(true)?>/components/com_wrd/assets/flash/uploadify.swf',
		    'script'    	: '<?php echo JURI::base(true)?>/components/com_wrd/classes/fileUploader.php',
		    'cancelImg' 	: '<?php echo JURI::base(true)?>/components/com_wrd/assets/images/cancel.png',
		    'folder'    	: '<?php echo str_ireplace('administrator', '', JURI::base(true)).'wrd' ?>',
		    'fileExt'		: '*.jpg;*.png',
	    	'fileDesc'		: 'Web Image Files (.JPG, .PNG)',
		    'auto'      	: true,
		    'scriptData'  	: {'typeupload':'logo','userid':<?php echo $this->user->id ?>},
		    'onComplete'  	: function(event, ID, fileObj, response, data) {
	    		obj = jQuery.parseJSON(response);
	        	jQuery('#imagefile').append('<div><img src="<?php echo JURI::base(true).'/../wrd/thumb/'?>'+obj.filename+'" /></div><div><a onclick="remove_image('+obj.fileid+')" href="javascript:void(null)">Remove</a></div>');
	        	jQuery('#logo').val(obj.fileid);
	        	jQuery('#image_uploadUploader').hide();
	      	}
	      	
		});
	
	});
	
	function remove_image(id){
		jQuery.ajax({
			url: "index.php?option=com_wrd&task=removefile",
			type: "POST",
			data: 'id='+id,
			success: function (res) {
				jQuery('#image_uploadUploader').show();
				jQuery('#imagefile').html('');
				
			}
		});
	}
</script>


<style>
	.uploadifyQueueItem {
	    background-color: #F5F5F5;
	    border: 2px solid #E5E5E5;
	    font: 11px Verdana,Geneva,sans-serif;
	    margin-top: 5px;
	    padding: 10px;
	    width: 300px;
	}
	
	#backgroundfile{
		width:160px;
		text-align: center;
	}

	#imagefile{
		text-align:left;
	}

	.image_prview {
	    background-color: #F5F5F5;
	    border: 2px solid #E5E5E5;
	    float: left;
	    margin: 2px;
	    padding: 5px;
	    text-align: center;
	    width: 160px;
	}
</style>

<form action="<?php echo JRoute::_("index.php?option=com_wrd")?>" method="post" name="adminForm" id="adminForm">
	<div class="row-fluid">
	    <fieldset class="adminform">
	    	<legend><?php echo JText::_('Details')?></legend>
			<table class="table table-striped adminlist">
				<tr>
					<td class="key">
						<label for="title"><?php echo JText::_('Company Name')?>:</label>
					</td>
					<td colspan="2">
						<input type="text" title="type" maxlength="50" size="50" value="<?php echo $this->data->name; ?>" id="companyname" name="name" class="companyname"/> *
					</td>
				</tr>
				
				<tr>
					<td class="key">
						<label for="title"><?php echo JText::_('Publish')?>:</label>
					</td>
					<td colspan="2">
						<?php echo $this->lists['published']; ?>
					</td>
				</tr>
            </table>
		</fieldset>
	</div>
	
	<div class="row-fluid">
	    <fieldset class="adminform">
	    	<legend><?php echo JText::_('Upload Logo')?></legend>
			<table class="table table-striped adminlist">
				<tr>
					<td>
						<div id="image_uploadUploader">
							<input id="logo_upload" name="logo_upload" type="file" />
						</div>
						<div id="imagefile">
						<?php if(!empty($this->filesalbum)):?>
							<div><img style="margin: 5px 5px 5px 0;" src="<?php echo JURI::base(true).'/../wrd/thumb/'.$this->filesalbum->name?>" /></div>
							<div><a onclick="remove_image('<?php echo $this->filesalbum->id; ?>')" href="javascript:void(null)">Remove</a></div>
							 <script type="text/javascript">
								jQuery(window).load(function(){
		        					jQuery('#image_uploadUploader').hide();
								 });
							</script>
						<?php endif;?>
						
						</div>
					</td>
				</tr>
            </table>
		</fieldset>
	</div>
	<input type="hidden" id="logo" name="logo" value="<?php echo $this->data->logo;?>" />
	<input type="hidden" name="created_by" value="<?php echo $this->user->id;?>" />
	<input type="hidden" name="controller" value="companyname" />
	<input type="hidden" name="option" value="com_wrd" />
	<input type="hidden" name="id" value="<?php echo (int)$this->data->id; ?>" />
	<input type="hidden" name="task" value="" />
	<?php echo JHTML::_( 'form.token' ); ?>
</form>